package com.meta.platform.contract.core.repository.impl;

import com.meta.platform.contract.core.mapper.ContractInvoiceReceiverMapper;
import com.meta.platform.contract.domain.tunnel.db.ContractInvoiceReceiverRepository;
import com.meta.platform.contract.intf.entity.ContractInvoiceReceiver;
import com.meta.platform.contract.intf.ro.ContractInvoiceReceiverRo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 发票收件人信息
 *
 * @Title: ContractInvoiceReceiverRepositoryImpl
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2020-12-08 15:53:38
 * @Version: v2.0
 */
@Service
public class ContractInvoiceReceiverRepositoryImpl implements ContractInvoiceReceiverRepository {

    @Autowired
    private ContractInvoiceReceiverMapper contractInvoiceReceiverMapper;

    /**
     * insert contractInvoiceReceiver info
     *
     * @param contractInvoiceReceiver:
     * @return void
     * @method insertContractInvoiceReceiver
     * @author M.simple
     * @date 2020-12-08 15:53:38
     */
    @Override
    public void insertContractInvoiceReceiver(ContractInvoiceReceiver contractInvoiceReceiver) {
        contractInvoiceReceiverMapper.insertContractInvoiceReceiver(contractInvoiceReceiver);
    }

    /**
     * batch insert contractInvoiceReceiver info
     *
     * @param contractInvoiceReceivers:
     * @return void
     * @method insertContractInvoiceReceiver
     * @author M.simple
     * @date 2020-12-08 15:53:38
     */
    @Override
    public void batchInsertContractInvoiceReceiver(List<ContractInvoiceReceiver> contractInvoiceReceivers) {
        contractInvoiceReceiverMapper.batchInsertContractInvoiceReceiver(contractInvoiceReceivers);
    }

    /**
     * update contractInvoiceReceiver info
     *
     * @param contractInvoiceReceiver:
     * @return int
     * @method updateContractInvoiceReceiver
     * @author M.simple
     * @date 2020-12-08 15:53:38
     */
    @Override
    public int updateContractInvoiceReceiver(ContractInvoiceReceiver contractInvoiceReceiver) {
        return contractInvoiceReceiverMapper.updateContractInvoiceReceiver(contractInvoiceReceiver);
    }

    /**
     * update contractInvoiceReceiver info by Pk
     *
     * @param contractInvoiceReceiver:
     * @return int
     * @method updateContractInvoiceReceiverByPk
     * @author M.simple
     * @date 2020-12-08 15:53:38
     */
    @Override
    public int updateContractInvoiceReceiverByPk(ContractInvoiceReceiver contractInvoiceReceiver) {
        return contractInvoiceReceiverMapper.updateContractInvoiceReceiverByPk(contractInvoiceReceiver);
    }

    /**
     * list contractInvoiceReceiver info
     *
     * @param contractInvoiceReceiver:
     * @return List<ContractInvoiceReceiver>
     * @method listContractInvoiceReceiver
     * @author M.simple
     * @date 2020-12-08 15:53:38
     */
    @Override
    public List<ContractInvoiceReceiver> listContractInvoiceReceiver(ContractInvoiceReceiverRo contractInvoiceReceiver) {
        return contractInvoiceReceiverMapper.listContractInvoiceReceiver(contractInvoiceReceiver);
    }

    @Override
    public void insertOrUpdate(List<ContractInvoiceReceiver> contractInvoiceReceivers) {
        for (ContractInvoiceReceiver contractInvoiceReceiver : contractInvoiceReceivers) {
            if (contractInvoiceReceiver.getId() != null) {
                contractInvoiceReceiverMapper.updateContractInvoiceReceiverByPk(contractInvoiceReceiver);
            } else {
                contractInvoiceReceiverMapper.insertContractInvoiceReceiver(contractInvoiceReceiver);
            }
        }
    }
}
